import tkinter as tk
from tkinter import messagebox

def login():
    username = username_entry.get()
    password = password_entry.get()

    # 这里可以替换为实际的用户名和密码验证逻辑
    if username == "1" and password == "1":
        messagebox.showinfo("登录成功", "欢迎回来，xu！")
    else:
        messagebox.showerror("登录失败", "用户名或密码错误！")

# 创建主窗口
root = tk.Tk()
root.title("登录")

# 创建用户名标签和输入框
username_label = tk.Label(root, text="用户名:")
username_label.grid(row=0, column=0, padx=10, pady=5)
username_entry = tk.Entry(root)
username_entry.grid(row=0, column=1, padx=10, pady=5)

# 创建密码标签和输入框
password_label = tk.Label(root, text="密码:")
password_label.grid(row=1, column=0, padx=10, pady=5)
password_entry = tk.Entry(root, show="*")
password_entry.grid(row=1, column=1, padx=10, pady=5)

# 创建登录按钮
login_button = tk.Button(root, text="登录", command=login)
login_button.grid(row=2, column=0, columnspan=2, padx=10, pady=5, sticky="we")

# 运行主循环
root.mainloop()
